#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File    :   mail.py
@Time    :   2024-07-31 15:35:25
@Author  :   chakcy 
@Email   :   947105045@qq.com
@description   :   邮箱服务
'''
import json 

from ..utils import websocket, WebSocketTask
from ..dependencies.celery import app as celery_app
from ..dependencies.celery import async_get_result

class SendMailTask(WebSocketTask):

    def business(self, data):
        return celery_app.send_task('send_mail', kwargs={"mail": data})
    
    async def callback(self, result, websocket):
        print(result)
        finally_result = await async_get_result(result)
        print(finally_result)
        await websocket.send_text(json.dumps(finally_result))

send_mail_task = SendMailTask()

class MailService:
    """
    邮件服务

    方法：
    - send_mail(websocket, redis) -> None
    """
    @staticmethod
    @websocket
    async def send_mail(websocket, redis):
        """
        发送邮件

        参数：
        - websocket: WebSocket
        - redis: RedisDependency

        返回值：None
        """
        return send_mail_task.handle
